home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 1 / Meeting Pearls Vol 1 (1994).iso / installed_progs / gfx / lise2.1 / lise / src / str / midstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-31  |  717 b   |  36 lines

  1. #include <stdio.h>
  2. main(argc,argv)
  3. int argc;
  4. char *argv[];
  5. {
  6. char c,s[256],z[256],e[256];
  7. int i,n,ss,es;
  8.  
  9. if(argc!=4) { /* print help message */
  10.    printf("midstr string start end\n returns the corresponding substring\n");
  11.    printf("\n(C) Rainer Kowallik\n");
  12. }
  13.  
  14.    strcpy(s,argv[1]);      /* source string */
  15.    ss=atoi(argv[2]);
  16.    es=atoi(argv[3]);
  17.    midstr(e,s,ss,es);
  18.    printf("%s\n",e);
  19.    exit(0);
  20. }
  21.  
  22.  
  23. /* -------------------------------------------------
  24.    return a substring from within a mainstring
  25.    ------------------------------------------------- */
  26. midstr(substr,str,ss,es)
  27. char  substr[],str[];
  28. short ss,es;
  29. {  short i,j;
  30.  
  31.    i=0;
  32.    for(j=ss; j <= es; j++) substr[i++]=str[j];
  33.    substr[i]=0;
  34. }
  35.  
  36.